package top.codecrab.springcloud.service.imlp;

import cn.hutool.core.util.IdUtil;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import top.codecrab.springcloud.service.MessageProvider;

import javax.annotation.Resource;

/**
 * EnableBinding：可以理解为是一个消息的发送管道的定义
 *
 * @author codecrab
 * @since 2021年05月18日 15:49
 */
@EnableBinding(Source.class)
public class MessageProviderImpl implements MessageProvider {

    /**
     * 消息的发送管道
     */
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String series = IdUtil.fastSimpleUUID();
        output.send(MessageBuilder.withPayload(series).build());
        System.out.println("********消息发送内容：" + series);
        return series;
    }

}
